package com.erification.web.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.erification.web.dao.AddressDao;
import com.erification.web.model.Address;
import com.erification.web.service.AddressService;
@Service("addressService")
public class AddressServiceImpl implements AddressService {
	@Resource
	private AddressDao addressDao;
	@Override
	public void saveAddress(Address address) {
		addressDao.save(address);
	}

	@Override
	public void modifyAddress(long user_id, Address address, String newAdd) {
		List<Address> list = addressDao.getAll(user_id);
		for(Address add : list){
			if(add.getAddress().equals(address.getAddress())){
				add.setAddress(newAdd);
				addressDao.update(add);
			}
		}
	}

	@Override
	public void deleteAddress(long id) {
		addressDao.delete(id);
	}

	@Override
	public List<Address> getAll(long user_id) {
		return addressDao.getAll(user_id);
	}

	@Override
	public Address get(long id) {
		return addressDao.getAddressById(id);
	}

}
